"""Pydantic 数据模型"""
from typing import List, Optional, Literal
from pydantic import BaseModel, Field


class ChunkData(BaseModel):
    """文本块数据"""
    chunk_id: str
    document_id: str
    filename: str
    index: int
    content: str
    token_count: int
    embedding: List[float]


class DocumentData(BaseModel):
    """文档元数据"""
    document_id: str
    filename: str
    upload_time: str
    file_path: str
    chunk_size: int
    chunks_count: int


class VectorStoreMetadata(BaseModel):
    """向量存储元数据"""
    total_documents: int
    total_chunks: int
    last_updated: Optional[str]


class VectorStore(BaseModel):
    """向量存储文件结构（扁平化结构）"""
    chunks: List[ChunkData]
    documents: List[DocumentData]
    metadata: VectorStoreMetadata


class DocumentUploadResponse(BaseModel):
    """文档上传响应"""
    success: bool = True
    document_id: str
    filename: str
    chunks_count: int
    message: str = "文档上传成功"


class DocumentInfo(BaseModel):
    """文档信息"""
    document_id: str
    filename: str
    upload_time: str
    chunks_count: int


class DocumentListResponse(BaseModel):
    """文档列表响应"""
    success: bool = True
    documents: List[DocumentInfo]


class DocumentDeleteResponse(BaseModel):
    """文档删除响应"""
    success: bool = True
    message: str = "文档删除成功"


class ChatRequest(BaseModel):
    """问答请求"""
    question: str = Field(..., description="用户问题")


class ChatStreamChunk(BaseModel):
    """流式响应数据块"""
    type: Literal["context", "token", "done"]
    content: Optional[str] = None
    similarity: Optional[float] = None


class HealthResponse(BaseModel):
    """健康检查响应"""
    status: str = "healthy"

